﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMD.DataModel;
using SmartMD.Manager.Common;
using SmartMD.DataModel.Entity;

namespace SmartMD.Manager.Specimens
{
    public class TooltipInfo : BusinessEntity
    {
        private string _sex;    //性别
        private int _age;    //年龄
        private string _followUpNo; //随访号
        private string _collecter;       //随访人
        private DateTime _followUpDate;   //随访时间
        private int _followUpTimes;  //随访周次
        private string _specType;     //标本类型
        private string _specification; //标本规格 
        private string _sitecode; //位置编码
        private string _followUper;
        private string _hostpitalNo;
        private string _pathologyNo;
        private string _customCode;

        public override void setValue(string key, Object value)
        {
            if (value is System.DBNull)
                return;
            switch (key.ToLower())
            {
                case "entityid":
                    this.Id = value.ToString();
                    break;
                case "patientname":
                    this.Name = value.ToString();
                    break;
                case "sex":
                    this.Sex = (string)value;
                    break;
                case "birthday":
                    this.Age = GetAgeByBirthday(DateTime.Parse(value.ToString()));
                    break;
                case "followupno":
                    this.FollowUpNo = (string)value;
                    break;
                case "collecter":
                    this.Collecter = (string)value;
                    break;
                case "collecttime":
                    this.FollowUpDate = DateTime.Parse(value.ToString());
                    break;
                case "followuptimes":
                    this.FollowUpTimes = int.Parse( (string)value);
                    break;
                case "spectype":                   
                    this.SpecType = (string)value;
                    break;
                case "specification":
                    this.Specification = (string)value;
                    break;
                case "pathologyno":
                    this.PathologyNo = value.ToString();
                    break;
                case "hostpitalno":
                    this.HostpitalNo = value.ToString();
                    break;
                case "followuper":
                    this.FollowUper = value.ToString();
                    break;
                case "sitecode":
                    this.Sitecode = value.ToString();
                    break;
                case "customcode":
                    this.CustomCode = value.ToString();
                    break;  
                    
            }
        }

        private int GetAgeByBirthday(DateTime date)
        {
            DateTime dateNow = System.DateTime.Now;
            int age = dateNow.Year - date.Year + 1;
            return age;
        }

        public string CustomCode
        {
            get
            {
                return _customCode;
            }
            set
            {
                _customCode = value;
                OnPropertyChanged(() => CustomCode);
            }
        }

        public string PathologyNo
        {
            get
            {
                return _pathologyNo;
            }
            set
            {
                _pathologyNo = value;
                OnPropertyChanged(() => PathologyNo);
            }
        }

        public string HostpitalNo
        {
            get
            {
                return _hostpitalNo;
            }
            set
            {
                _hostpitalNo = value;
                OnPropertyChanged(() => HostpitalNo);
            }
        }
        public string FollowUper
        {
            get
            {
                return _followUper;
            }
            set
            {
                _followUper = value;
                OnPropertyChanged(() => FollowUper);
            }
        }

        public string Sitecode
        {
            get
            {
                return _sitecode;
            }
            set
            {
                _sitecode = value;
                OnPropertyChanged(() => Sitecode);
            }
        }
        public int FollowUpTimes
        {
            get
            {
                return _followUpTimes;
            }
            set
            {
                _followUpTimes = value;
                OnPropertyChanged(() => FollowUpTimes);
            }
        }

        public String FollowUpNo
        {
            get
            {
                return _followUpNo;
            }
            set
            {
                _followUpNo = value;
                OnPropertyChanged(() => FollowUpNo);
            }
        }
        public String Specification
        {
            get
            {
                return _specification;
            }
            set
            {
                _specification = value;
                OnPropertyChanged(() => Specification);
            }
        }
        public String Collecter
        {
            get
            {
                return _collecter;
            }
            set
            {
                _collecter = value;
                OnPropertyChanged(() => Collecter);
            }
        }

        [CheckValue("标本定义“采集时间”不能为空")]
        public DateTime FollowUpDate
        {
            get
            {
                return _followUpDate;
            }
            set
            {
                _followUpDate = value;
                OnPropertyChanged(() => FollowUpDate);
            }
        }

        public String SpecType
        {
            get
            {
                return _specType;
            }
            set
            {               
                _specType = value;
                DictionaryType dictType = CacheUtil.GetInstance().GetDictionaryByName("标本类型");
                foreach(var item in dictType.Items)
                {
                    if ((item as DictionaryItem).Code == value)
                    {
                        _specType = (item as DictionaryItem).Name;
                        break;
                    }
                }
                OnPropertyChanged(() => SpecType);
            }
        }

        public String Sex
        {
            get
            {
                return _sex;
            }
            set
            {
                _sex = value;
                OnPropertyChanged(() => Sex);
            }
        }
        public int Age
        {
            get
            {
                return _age;
            }
            set
            {
                _age = value;
                OnPropertyChanged(() => Age);
            }
        }
    }
}
